#!/bin/bash

# Test that quacreduce argument parsing works correctly.
#
# Copyright (c) Los Alamos National Security, LLC, and others.

. ./environment.sh

cd $DATADIR

set +e
exec 2>&1  # send stderr to stdout to make output more readable

echo '*** Check input files for unique names'
x quacreduce --map cat --reduce cat foo/bar.txt baz/qux.txt
echo $?
x quacreduce --map cat --reduce cat foo/bar.txt baz/bar.txt
echo $?

echo '*** Check specification of --python, --map, --reduce'

echo '*** these should succeed'
#x quacreduce --python foo job1 input.txt
#echo $?
x quacreduce --map foo --reduce bar input.txt
echo $?
x quacreduce --python foo --map bar input.txt
echo $?
x quacreduce --python foo --reduce bar input.txt
echo $?

echo '*** these should fail'
x quacreduce --notimes input.txt
echo $?
x quacreduce --notimes --map bar input.txt
echo $?
x quacreduce --notimes --reduce bar input.txt
echo $?
x quacreduce --notimes --python foo --map bar --reduce baz input.txt
echo $?

echo '*** Check that job fails if the map or reduce commands fail'
x quacreduce --notimes --map false --reduce true /dev/null
x make --quiet
x quacreduce --notimes --map true --reduce false /dev/null
x make --quiet

true  # don't pass make's failure code to cmdtest
